package com.guigu.ssyx.product.controller;


import com.atguigu.ssyx.vo.product.SkuInfoQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.ssyx.common.result.Result;
import com.guigu.ssyx.product.entity.SkuInfo;
import com.guigu.ssyx.product.entity.vo.SkuInfoVo;
import com.guigu.ssyx.product.service.SkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * sku信息 前端控制器
 * </p>
 *
 * @author liuyang
 * @since 2025-09-10
 */
@RestController
@RequestMapping("/admin/product/skuInfo")
public class SkuInfoController {

    @Autowired
    private SkuInfoService skuInfoService;

    @GetMapping("{page}/{limit}")
    public Result index(@PathVariable Long page, @PathVariable Long limit, SkuInfoQueryVo skuInfoQueryVo){
        Page<SkuInfo> skuInfoPage = new Page<>(page, limit);
        IPage<SkuInfo> pageModel = skuInfoService.selectPage(skuInfoPage, skuInfoQueryVo);

        return Result.ok(pageModel);

    }

    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id){
        SkuInfoVo skuInfoVo = skuInfoService.getSkuVoInfo(id);
        return Result.ok(skuInfoVo);
    }

    @PostMapping("save")
    public Result save(@RequestBody SkuInfoVo skuInfoVo){
        skuInfoService.saveSkuInfo(skuInfoVo);
        return Result.ok(null);
    }

    @PutMapping("update")
    public Result updateById(@RequestBody SkuInfoVo skuInfoVo){
        skuInfoService.updateSkuInfo(skuInfoVo);
        return Result.ok(null);
    }

    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id){
        skuInfoService.removeById(id);
        return Result.ok(null);
    }

    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody Long[] ids){
        skuInfoService.removeByIds(java.util.Arrays.asList(ids));
        return Result.ok(null);
    }

    @GetMapping("check/{skuId}/{status}")
    public Result check(@PathVariable Long skuId, @PathVariable Integer status){
        SkuInfo skuInfo = skuInfoService.getById(skuId);
        skuInfo.setCheckStatus(status);
        skuInfoService.updateById(skuInfo);

        return Result.ok(null);
    }

   @GetMapping("publish/{skuId}/{status}")
    public Result publish(@PathVariable Long skuId, @PathVariable Integer status) {
       skuInfoService.publish(skuId, status);

       return Result.ok(null);
   }

   @GetMapping("isNewPerson/{skuId}/{status}")
    public Result isNewPerson(@PathVariable Long skuId, @PathVariable Integer status) {
        SkuInfo skuInfo1 = new SkuInfo();
        skuInfo1.setId(skuId);
        skuInfo1.setIsNewPerson(status);
        skuInfoService.updateById(skuInfo1);
       return Result.ok(null);
   }

}

